//
//  ETitleTextFieldView.m
//  Common
//
//  Created by shiqing guo on 2018/8/6.
//  Copyright © 2018年 www.bitkinetic.com. All rights reserved.
//

#import "ETitleTextFieldView.h"
#import "Macro.h"
#import "UIView+DDAddition.h"

@interface ETitleTextFieldView () <UITextFieldDelegate>
@property (nonatomic, strong) UILabel *lblTitle;
@property (nonatomic, strong) UITextField *txfContet;
@end

@implementation ETitleTextFieldView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.frame = frame;
        [self addSubviews];
    }
    return self;
}

- (void)addSubviews
{
    [self addSubview:self.lblTitle];
    [self addSubview:self.txfContet];
}

- (void)layoutSubviews
{
    self.txfContet.right = self.width;
    self.lblTitle.height = self.height;
    self.txfContet.height = self.height;
}

- (void)setStrTitle:(NSString *)strTitle
{
    _strTitle = strTitle;
    self.lblTitle.text = strTitle;
    [self setNeedsLayout];
}

- (void)setStrPlaceholder:(NSString *)strPlaceholder
{
    _strPlaceholder = strPlaceholder;
    self.txfContet.placeholder = strPlaceholder;
    [self setNeedsLayout];
}

- (void)setWidthOfTitle:(CGFloat)widthOfTitle
{
    _widthOfTitle = widthOfTitle;
    self.lblTitle.width = widthOfTitle;
    [self setNeedsLayout];
}

- (void)setWidthOfContent:(CGFloat)widthOfContent
{
    _widthOfContent = widthOfContent;
    self.txfContet.width = widthOfContent;
    [self setNeedsLayout];
}

#pragma mark - 返回数据


#pragma mark - 懒加载
- (UILabel *)lblTitle
{
    if (!_lblTitle) {
        _lblTitle = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 1.0f, 1.0f)];
        _lblTitle.font = SystemFont(16.0f);
        _lblTitle.textColor = [EPColor epColor_TitleBlack];
    }
    return _lblTitle;
}


- (UITextField *)txfContet
{
    if (!_txfContet) {
        _txfContet = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 1.0f, 1.0f)];
        _txfContet.font = SystemFont(16.0f);
        _txfContet.textColor = [EPColor epColor_TitleBlack];
        _txfContet.delegate = self;
    }
    return _txfContet;
}

#pragma mark - UITextFieldDelegate
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    NSString *toBeString = [textField.text stringByReplacingCharactersInRange:range withString:string];
    if (self.iMaxLength < toBeString.length) return NO;
    return YES;
}

- (NSString *)getContent
{
    return self.txfContet.text;
}

@end

